class Solution {
public:
    int searchInsert(vector<int>& nums, int target) 
    {

        int max = nums.size();
        int min = 0;

        while(min < max)
        {
            int mid = min + (max - min) / 2;

            if(nums[mid] == target)
                return mid;
            else if(nums[mid] > target)
                max = mid;
            else if(nums[mid] < target)
                min = mid + 1;
        }
        
        return max;
    }
};

//二分查找法，时间为0ms